package org.lvgo.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * 或者过滤器,满足其中一种即可
 *
 * @author lvgo
 * @version 1.0
 * @date 2018/9/21 0021 17:10
 */
public class OrFilter implements Criteria {
    private Criteria c1;
    private Criteria c2;

    public OrFilter(Criteria c1, Criteria c2) {
        this.c1 = c1;
        this.c2 = c2;
    }

    @Override
    public List<Person> filterPerson(List<Person> people) {
        List<Person> people1 = c1.filterPerson(people);
        List<Person> persons = new ArrayList<>(people1);
        List<Person> people2 = c2.filterPerson(people);
        people2.forEach(person -> {
            if (!persons.contains(person)) {
                persons.add(person);
            }
        });
        return persons;
    }
}
